home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / c / cgagrafa.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  3.1 KB  |  183 lines

  1. ;
  2.  
  3. ; grafix --- cgagrafa.asm
  4.  
  5. ;
  6.  
  7. ; stuff to plot points fast in 8086 assembler (BLEECH!!!)
  8.  
  9. ;
  10.  
  11. ; Written 4/87 by Scott Snyder (ssnyder@romeo.caltech.edu or @citromeo.bitnet)
  12.  
  13. ;
  14.  
  15. ; Modified 5/29/87 by sss to allow for different memory models
  16.  
  17. ;
  18.  
  19.  
  20.  
  21.     title    cgagrafa
  22.  
  23.  
  24.  
  25. include macros.ah
  26.  
  27.  
  28.  
  29. sseg
  30.  
  31. endss
  32.  
  33.  
  34.  
  35. g_oddoff equ    02000h
  36.  
  37. g_linsiz equ    80
  38.  
  39.  
  40.  
  41. dseg
  42.  
  43.  
  44.  
  45.     ex g_drawbuf,     dword
  46.  
  47.     ex g_pixbyte,     word
  48.  
  49.     ex g_bitpix,      word
  50.  
  51.     ex g_colormask,   byte
  52.  
  53.     ex g_cmask_tbl,   byte
  54.  
  55.     ex g_hicolormask, byte
  56.  
  57.     ex g_xor,         word
  58.  
  59.     ex g_xcliplo,     word
  60.  
  61.     ex g_xcliphi,     word
  62.  
  63.     ex g_ycliplo,     word
  64.  
  65.     ex g_ycliphi,     word
  66.  
  67.  
  68.  
  69. endds
  70.  
  71.  
  72.  
  73. cseg _cgagrafa
  74.  
  75.  
  76.  
  77. ; plot a point. ax = y; bl = c; cx = x;
  78.  
  79.  
  80.  
  81. pBegin    plot
  82.  
  83.  
  84.  
  85.     les    si, g_drawbuf        ; get address of buffer
  86.  
  87.     sar    ax, 1            ; y /= 2
  88.  
  89.     jnc    p1            ; add in offset if it was odd
  90.  
  91.     add    si, g_oddoff
  92.  
  93. p1:    mov    dx, g_linsiz        ; y * g_linsiz
  94.  
  95.     mul    dx
  96.  
  97.     add    si, ax            ; add to offset
  98.  
  99.     mov    ax, cx            ; x to AC (ohhh... what symmetry!)
  100.  
  101.     mov    dx, 0
  102.  
  103.     div    g_pixbyte
  104.  
  105.     add    si, ax            ; add quotient to offset (now complete)
  106.  
  107.     and    bl, g_colormask        ; get cmask
  108.  
  109.     mov    bl, g_cmask_tbl[bx]
  110.  
  111.     mov    cx, g_bitpix        ; only works for bitpix = 0 or 1!
  112.  
  113.     dec    cx
  114.  
  115.     shl    dx, cl            ; dx = mask shift count
  116.  
  117.     mov    cx, dx
  118.  
  119.     mov    dl, g_hicolormask    ; get mask
  120.  
  121.     shr    dl, cl            ; shift it
  122.  
  123.     and    bx, dx            ; bx = cmask & mask
  124.  
  125.     mov    al, es:[si]        ; get image byte
  126.  
  127.     cmp    g_xor, 0        ; xor mode?
  128.  
  129.     jne    p2
  130.  
  131.     not    dl            ; no - (*ptr & ~mask) | (cmask & mask)
  132.  
  133.     and    al, dl
  134.  
  135.     or    al, bl
  136.  
  137.     jmp    p3
  138.  
  139. p2:    xor    al, bl            ; yes - *ptr ^ (cmask & mask)
  140.  
  141. p3:    mov    es:[si], al        ; done!
  142.  
  143.     ret
  144.  
  145.  
  146.  
  147. pEnd    plot
  148.  
  149.  
  150.  
  151. ;
  152.  
  153. ; C interface for point plotter
  154.  
  155. ;
  156.  
  157. ; CGA_point(x, y, c)
  158.  
  159. ;
  160.  
  161.  
  162.  
  163. pBegin    CGA_point
  164.  
  165.     push    bp
  166.  
  167.     mov    bp, sp
  168.  
  169.     push    si
  170.  
  171.     push    di
  172.  
  173.  
  174.  
  175.     mov    ax, [bp+argbase+2]
  176.  
  177.     mov    bx, [bp+argbase+4]
  178.  
  179.     mov    cx, [bp+argbase]
  180.  
  181.     call    plot
  182.  
  183.  
  184.  
  185.     pop    di
  186.  
  187.     pop    si
  188.  
  189.     mov    sp, bp
  190.  
  191.     pop    bp
  192.  
  193.     ret
  194.  
  195.  
  196.  
  197. pEnd    CGA_point
  198.  
  199.  
  200.  
  201. ;
  202.  
  203. ; write for pixels for circle drawing
  204.  
  205. ;
  206.  
  207. ; void CGA_write_pix(x1, y1, x2, y2, c)
  208.  
  209. ;
  210.  
  211.  
  212.  
  213. pBegin    CGA_write_pix
  214.  
  215.  
  216.  
  217.     push    bp
  218.  
  219.     mov    bp, sp
  220.  
  221.     push    si
  222.  
  223.     push    di
  224.  
  225.  
  226.  
  227.     mov    bx, [bp+argbase+8]    ; bx = c (for plot)
  228.  
  229.     mov    cx, [bp+argbase]    ; cx = x1
  230.  
  231.     cmp    cx, g_xcliplo        ; check for clipping
  232.  
  233.     jb    w2
  234.  
  235.     cmp    cx, g_xcliphi
  236.  
  237.     ja    w2
  238.  
  239.  
  240.  
  241.     mov    ax, [bp+argbase+2]    ; ax = y1
  242.  
  243.     cmp    ax, g_ycliplo        ; do clipping
  244.  
  245.     jb    w1
  246.  
  247.     cmp    ax, g_ycliphi
  248.  
  249.     ja    w1
  250.  
  251.  
  252.  
  253.     push    bx            ; plot (x1, y1)
  254.  
  255.     push    cx
  256.  
  257.     call    plot
  258.  
  259.     pop    cx
  260.  
  261.     pop    bx
  262.  
  263.  
  264.  
  265. w1:    mov    ax, [bp+argbase+6]    ; ax = y2
  266.  
  267.     cmp    ax, g_ycliplo
  268.  
  269.     jb    w2
  270.  
  271.     cmp    ax, g_ycliphi
  272.  
  273.     ja    w2
  274.  
  275.  
  276.  
  277.     push    bx            ; plot (x1, y2)
  278.  
  279.     call    plot
  280.  
  281.     pop    bx
  282.  
  283.  
  284.  
  285. w2:    mov    cx, [bp+argbase+4]    ; cx = x2
  286.  
  287.     cmp    cx, g_xcliplo
  288.  
  289.     jb    w4
  290.  
  291.     cmp    cx, g_xcliphi
  292.  
  293.     ja    w4
  294.  
  295.  
  296.  
  297.     mov    ax, [bp+argbase+2]    ; ax = y1
  298.  
  299.     cmp    ax, g_ycliplo        ; do clipping
  300.  
  301.     jb    w3
  302.  
  303.     cmp    ax, g_ycliphi
  304.  
  305.     ja    w3
  306.  
  307.  
  308.  
  309.     push    bx            ; plot (x2, y1)
  310.  
  311.     push    cx
  312.  
  313.     call    plot
  314.  
  315.     pop    cx
  316.  
  317.     pop    bx
  318.  
  319.  
  320.  
  321. w3:    mov    ax, [bp+argbase+6]    ; ax = y2
  322.  
  323.     cmp    ax, g_ycliplo
  324.  
  325.     jb    w4
  326.  
  327.     cmp    ax, g_ycliphi
  328.  
  329.     ja    w4
  330.  
  331.  
  332.  
  333.     call    plot            ; plot (x2, y2)
  334.  
  335.  
  336.  
  337. w4:    pop    di
  338.  
  339.     pop    si
  340.  
  341.     mov    sp, bp
  342.  
  343.     pop    bp
  344.  
  345.     ret
  346.  
  347.  
  348.  
  349. pEnd    CGA_write_pix
  350.  
  351.  
  352.  
  353.     df_ CGA_point
  354.  
  355.     df_ CGA_write_pix
  356.  
  357.  
  358.  
  359. endcs    _cgagrafa
  360.  
  361.  
  362.  
  363. end
  364.  
  365.